<template>
  <div class="GL_container">
    <Card class="marginB10">
      <div class="pt-header padding0 marginB10">
        <Input
          search
          enter-button="搜索"
          @on-search="searchTm"
          placeholder="专利名称,申请号,申请人名称等"
          v-model="search_key"
          style="width:400px;"
        />

        <div class="pt-menu">
          <span class="marginR30" v-show="t_num>0">已管理：{{t_used_num}}/{{t_num}}笔</span>
          <span class="marginR30 pointer underline cRed" v-show="typeof t_num === 'number' && t_num<=0" @click="$app.todayMoneyYes(888)">管理次数已用完，点击购买</span>
          <span class="textLink" @click="$router.push({name:'patentDo'})">专利服务</span>
          <span class="cCCC">|</span>
          <span class="textLink" @click="jR_dao">专利导入</span>
          <span class="cCCC">|</span>
          <span class="textLink" @click="del">删除</span>
          <span class="cCCC">|</span>
          <span class="textLink" @click="clear">清空所有数据</span>
        </div>
      </div>

      <div>
        <CheckboxGroup v-model="state_L" class="inlineBlock marginR20" @on-change="searchTm">
          <Checkbox v-for="(val,i) in sA" :key="i" :label="val.key"  class="marginR20">{{val.state_name}}({{val.count}})</Checkbox>
          <Button
            type="primary"
            ghost
            class="marginR10"
            shape="circle"
            size="small"
            @click="qKong"
          >清 空</Button>
        </CheckboxGroup>
      </div>
      
    </Card>
    <Card >
      <Table
        :data="tData"
        :columns="columns"
        stripe
        border
        class="marginB10"
        :loading="loading"
        :height="$app.winHeight-295"
        @on-selection-change="onSelect"
        @on-sort-change="paiXuGo"
      ></Table>
      <Page
        :total="total"
        show-total
        show-sizer
        show-elevator
        size="small"
        :page-size="pageSize"
        :page-size-opts="$app.pageAll.pageSizeOpts"
        :current="page"
        @on-change="loadMore"
        @on-page-size-change="changePageSize"
      ></Page>
    </Card>

    <PABox ref="PABox" />
    <!-- type : 1专利 2商标 3版权 ，显示 temp页面；8专利 9商标 10版权，隐藏 temp页面-->
    <Temp ref="Temp" :type="8" />
  </div>
</template>

<script>
import colB from "@$@/js/tableColumns/colB";
import PABox from "@$@/_service/PABox";
import Temp from "@$@/_service/temp";
export default {
  name: "patentAdmin",
  components: {PABox,Temp},
  data() {
    let data = {
      t_used_num:0,//分子
      t_num:'',//分母
      columns: [],
      tData: [], // 数据
      sA: [
        {key: 1,state_name: "申请中", count: 0},
        {key: 2,state_name: "已授权", count: 0},
        {key: 3,state_name: "已失效", count: 0},
        {key: 4,state_name: "其他", count: 0},
      ],//多选框内容 数组
      state_L: []//多选框，选中的内容
    };
    let tool = {
      loading: true,
      selectMore: [], //多选，选中的栏位

      search_key: "", // 搜索关键字
      total: 0,
      page: 1,
      pageSize: $app.pageAll.pageSize, //分页条数，最低15条
      order: "created_at", // 排序字段
      order_type: "desc" //asc
    };
    return Object.assign(data, tool);
  },
  // 挂载
  mounted() {
    this.getTmList();
  },
  // 绑定方法
  methods: {
    //搜索条件切换
    inputDd(){

    },
    // 搜索
    searchTm() {
      this.page = 1;
      this.$nextTick(() => {
        this.getTmList();
      });
    },
    paiXuGo(obj) {
      

      let { order_type } = this;

      if(this.order==obj.key){
        if (order_type == "asc") {
          this.order_type = "desc";
        } else {
          this.order_type = "asc";
        }
      }else{
        if(obj.order=='normal'){
          this.order_type = 'desc';
        }else{
          this.order_type = obj.order;
        }
      }
      
      this.order=obj.key;//排序字段更新
      

      this.$nextTick(() => {
        this.getTmList();
      });
    },
    // 多选模式触发
    onSelect(list, row) {
      let selectMore = [];
      list.forEach((val, i) => {
        selectMore.push(val.patent_manage_id);
      });
      this.selectMore = selectMore;
    },
    //清空所有
    clear() {
      $app.confirm("您确定要删除所有管理的专利吗?", "温馨提示", {
        yesFun: () => {
          //点击了确认
          $ajax.z_get_clear(null, res => {
            this.page = 1;
            this.tData = [];
            this.selectMore=[];
            this.total = 0;
            this.t_used_num=0;//分子

            //多选框内容 数组 清空
            this.sA=[
              {key: 1,state_name: "申请中", count: 0},
              {key: 2,state_name: "已授权", count: 0},
              {key: 3,state_name: "已失效", count: 0},
              {key: 4,state_name: "其他", count: 0},
            ];
            this.state_L=[];

            $app.toast(res.msg, true);
          });
        }
      });
    },
    // 批量删除
    del() {
      let {
        selectMore:ids
      }=this;
      if($app.judgeData(ids)){
        $app.confirm("您确定要删除?", "温馨提示", {
          yesFun: () => {
            $ajax.z_get_del({ ids: JSON.stringify(ids) }, res => {
              $app.toast(res.msg, true);
              this.page = 1;
              this.$nextTick(() => {
                this.getTmList();
              });
            });
          }
        });
      }else{
        this.$Message.error({content: "请选择要删除的专利"});
      }
    },
    //清空搜索条件
    qKong(){
      this.state_L=[];
      this.searchTm();
    },
    // 获取数据
    getTmList() {
      let {
        page,
        pageSize,
        search_key: keyword,
        order,
        order_type,
        state_L
      } = this;

      let objGo={ page, pageSize, keyword, order, order_type };
      if($app.judgeData(state_L)){
        objGo.states=JSON.stringify(state_L);
      }

      this.loading = true;
      this.columns = [];
      this.selectMore=[];
      this.tData=[];

      this.huoDci();//已用次数

      $ajax.z_get_patentList(objGo,res => {
          this.columns = colB.list(this);

          this.loading = false;
          this.tData = res.data.list;
          this.total = res.data.total;
          this.total_page = res.data.total_page;

          //筛选添加赋值
          this.sA=res.data.state_list;
        }
      );
    },
    // 加载更多
    loadMore(page) {
      this.page = page;
      this.$nextTick(() => {
        this.getTmList();
      });
    },
    // 数据返回条
    changePageSize(pageSize) {
      this.page = 1;
      this.pageSize = pageSize;
      this.$nextTick(() => {
        this.getTmList();
      });
    },

    // 续费
    woRb(num){
      this.$refs['Temp'].show119Box(num,true);
    },

    //我的资产
    huoDci(){
      $ajax.wZcList(({ role_service_item_list, service_item_list }) => {
        if($app.judgeData(service_item_list.patent_manage)){
          this.t_used_num=service_item_list.patent_manage.used_num;
          this.t_num=service_item_list.patent_manage.num;
        }else{
          this.t_used_num=0;
          this.t_num=0;
        }
      });
    },


    //年费记录
    xwtwPP(patent_no,patent_name){
      $ajax.z_pMpF(patent_no,resData=>{
        this.$refs['PABox'].showBox=true;
        this.$refs['PABox'].titleT=patent_name;

        this.$refs['PABox'].data1=resData.not_pay;//未缴费信息
        this.$refs['PABox'].data2=resData.paid;//已缴费信息

        //return 退费信息
        this.$refs['PABox'].data3=resData.return;
        //late 滞纳金
        this.$refs['PABox'].data4=resData.late;
      });
    },

    //导入判断
    jR_dao(){
      let {
        t_num,
        t_used_num
      }=this;
      if(t_num>0 && t_used_num<t_num){
        this.$router.push({
          name:'brandDo',
          query:{
            typeP:'importP'
          }
        });
      }else{
        $app.alert('管理次数已经用完请购买套餐','温馨提示',()=>{
          $app.todayMoneyYes(888);
        });
      }
    }
    
  }
};
</script>
